#ifndef MODELITEMSET_H
#define MODELITEMSET_H


#include "itemmodel_global.h"
#include "modelitem.h"


template <typename T>
class Q_DECL_EXPORT ModelItemSet : public ModelItem
{
public:

    T* createItem(const QString& name = QString())
    {
        T* item = new T(this);
        item->setName(name);
        return item;
    }

    int count() const
    {
        return items().count();
    }

    QList<T*> items() const
    {
        return findChildren<T*>(QString(), Qt::FindDirectChildrenOnly);
    }

    int childTypeId() const
    {
        return qMetaTypeId<T*>();
    }


protected:

    /// \brief You need to inherit from this template and use Q_OBJECT macro there.

    ModelItemSet(QObject* parent = 0) :
        ModelItem(parent)
    {
        qRegisterMetaType<T*>();
    }


    ModelItemSet(const ModelItemSet<T>& other) :
        ModelItem(other)
    {
    }

};

#endif // MODELITEMSET_H
